class Solution(object):
    def myPow(self, x, n):
        """
        :type x: float
        :type n: int
        :rtype: float
        """
        if n == 0:
            return 1
        if n == 1:
            return x
        
        y = self.myPow(x, abs(n)/2)
        if n >= 0:
            return y * y * self.myPow(x, abs(n)%2)
        else:
            return 1/(y * y * self.myPow(x, abs(n)%2))
